通过ajax显示和隐藏primefaces选项卡(show and hide primefaces tab via ajax)
我有下面的primefaces选项卡视图的版本。
<p:tabview> <p:tab id="1"> <p:selectOneMneu value="#{bean.answer}> <f:selectItem itemValue="yes"/> <f:selectItem itemValue="no" /> </p:selectOneMenu> </p:tab> <p:tab id="2" rendered=#{bean.answer eq 'yes'} > <h:outputText="answer is Yes."/> </p:tab> <p:tab id="3" rendered=#{bean.answer eq 'no'} > <h:outputText="answer is No."/> </p:tab> </p:tabView>
有一个托管bean捕获“yes”或“no”的选定值。 评估值时,取决于答案,其中一个选项卡将被隐藏。 一旦您对所做的选择感到满意,他/她就会点击一个提交按钮来发布数据。
我的问题是如果用户在按提交按钮之前改变了他/她的想法。 返回到下拉菜单(selectOneMenu),然后将值从“是”更改为“否”。 然后,我希望动态的豆将检索更新的答案,而不刷新整个xhtml页面。 这似乎是阿贾克斯的答案,但我不知道如何解决它。
I have following water down version of primefaces tab view.
<p:tabview> <p:tab id="1"> <p:selectOneMneu value="#{bean.answer}> <f:selectItem itemValue="yes"/> <f:selectItem itemValue="no" /> </p:selectOneMenu> </p:tab> <p:tab id="2" rendered=#{bean.answer eq 'yes'} > <h:outputText="answer is Yes."/> </p:tab> <p:tab id="3" rendered=#{bean.answer eq 'no'} > <h:outputText="answer is No."/> </p:tab> </p:tabView>
There is a managed bean which captures the selected value of either "yes" or "no". When the value is evaluated, depends on the answer, one of the tabs will be hidden. Once you are satisfied with the choice made, he/she clicks a submit button to post the data.
My question is what if a user changes his/her mind before pressing a submit button. Go back to drop down menu (selectOneMenu) then changes the value from "yes" to "no". Then I am hoping dynamically the bean would retrieve updated answer without refreshing entire xhtml page. It seems like ajax is the answer but I am not sure how to resolve it.
原文:https://stackoverflow.com/questions/41190800
最满意答案
这在PHP中不是本地可能的。 有些解决方法像使用数组来传递所有参数而不是一行参数, 但是它们有很大的缺点 。
我能想到的最好的手动解决方法是定义一个常数值,该常数值不能与实际值相冲突。 例如,对于不能为
-1
的参数:define("DEFAULT_ARGUMENT", -1);
并为此进行测试:
function($foo = DEFAULT_ARGUMENT, $bar = false){}
This is not natively possible in PHP. There are workarounds like using arrays to pass all parameters instead of a row of arguments, but they have massive downsides.
The best manual workaround that I can think of is defining a constant with an arbitrary value that can't collide with a real value. For example, for a parameter that can never be
-1
:define("DEFAULT_ARGUMENT", -1);
and test for that:
function($foo = DEFAULT_ARGUMENT, $bar = false){}
相关问答
更多-
你不能使用一个函数作为默认参数值: 默认值必须是常量表达式,而不是(例如)变量,类成员或函数调用。 ( 从PHP文档提取 ) 您应该将默认值设置为该函数: function myFunction($month, $year = null) { if(!isset($year)) { $year = date('Y'); } echo $year.', '.$month; } myFunction('June', '2006'); // 2006, June myFunctio ...
-
是的,函数被允许作为默认参数。 请参阅2003标准的8.3.6 / 5中的示例 Yes, functions are permitted as default arguments. See the example in 8.3.6/5 of the 2003 standard
-
这在PHP中不是本地可能的。 有些解决方法像使用数组来传递所有参数而不是一行参数, 但是它们有很大的缺点 。 我能想到的最好的手动解决方法是定义一个常数值,该常数值不能与实际值相冲突。 例如,对于不能为-1的参数: define("DEFAULT_ARGUMENT", -1); 并为此进行测试: function($foo = DEFAULT_ARGUMENT, $bar = false){} This is not natively possible in PHP. There are workaro ...
-
你可能想要的是使函数更复杂: def print_name(name=None): if not name: name='lisa' print name ...所以你可以简单地调用它: print_name(name) if not name:只要name是任何假的,都将为真 - 无论是默认值None还是空字符串。 这可能不是你想要的 - 也许你想明确地将默认值设置为''并检查if name == '':例如 - 但它通常是一个很好的第一个猜测。 所以: >>> nam ...
-
现在这在PHP中是不可能的。 您必须手动传递默认值,如: test("a", "b", "f"): 有关于此的RFC: https : //wiki.php.net/rfc/skipparams但它还没有取得任何成功。 This is not possible in PHP nowadays. You have to pass the default value manually like: test("a", "b", "f"): There exists a RFC about this: http ...
-
函数指针和默认参数(Function pointer and default argument)[2022-07-06]
C没有默认参数。 我假设有一个很好的理由你想要两个单独的函数指针,而不是直接用所需的flag参数调用funcPtr 。 如果是这样,为什么不在模块中只有两个包装函数? void (* funcPtr)(int argument, bool flag); void setFuncPtr(void (* func)(int argument, bool flag)) { funcPtr = func; } void funcTrue(int argument) { funcPtr(argument, ... -
为什么不使用None ? def greet(name, greeting='Hello', punctuation='!'): return greeting+' '+name+punctuation def greet_with_hi(name, punctuation=None): if punctuation: return greet(name, 'Hi', punctuation) else: return greet(name, 'Hi ...
-
在你的f3() , "hello1"不是函数形式参数列表中xlab的默认值。 它是在函数体中提供的值,所以无法覆盖它: f3 <- function(...){ plot(xlab="hello1", ...)} 我怀疑你的意思,而是做这样的事情。 f1 <- function(...){ f2(...)} f2 <- function(...){ f3(...)} f3 <- function(..., xlab="hello1") plot(..., xlab=xlab) ## Then check ...
-
如何告诉PHP在函数调用中使用默认参数?(How to tell PHP to use default parameter in a function call? [duplicate])[2023-01-15]
将默认参数放在最后,然后不要在函数调用中填写参数。 例: function nums($c, $a = 1, $b = 2){ echo "$a, $b, $c"; } nums(3); 可以通过将默认参数添加到函数调用来覆盖它们: function nums($c, $a = 1, $b = 2){ echo "$a, $b, $c"; } nums(3, 12, 27); Put the default parameters at the end, then don't fill ... -
正如您在原始帖子的评论中所建议的那样,lambda不能用作可选参数。 另一种方法是使用没有参数的版本和带有委托参数的版本重载函数(在您的示例中为test)。 Delegate Function OperationDelegate(ByVal x As Double) As Double Public Function test() As Double Return test(AddressOf OperationDelegate) End Function Public Function test ...