• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to dynamically set the action attribute

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a commandbutton declared as:

<af:commandButton text="#{res[\'button.delete\']}"
id="cmdDelete"
action=""
on_click="return confirmAction(this)"/>

Then I have a javascript for the confirmAction:

function confirmAction(obj){
obj.action = "#{backingTest.testMethod}";
return true;
}

This doesn't seem to set the action. Am I doing it wrong?
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, this is not the way.

Instead do:

JSF

JS
[ October 10, 2006: Message edited by: B L Scholtz ]
 
Joseph Siao
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the answer.

But I need to set the action dynamically. I will be having 4 conditions, and each condition will call a different method on my backing bean.

Something like this:

function confirmAction(obj){
if(value1){
obj.action = "#{backing.method1}";
return true;
}else if(value2){
obj.action = "#{backing.method2}";
return true;
}else if(value3){
obj.action = "#{backing.method3}";
}else {
return false;
}
}

suggestions please.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where does value1, value2, etc come from?
 
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
cant you have one method in your backing bean that looks at value1,value2... and calls the appropriate method?

h:commandButton value="submit" action="#{myBean.action}" on_click="validate();" />


public String action(){
if (value1) return method1;
if (value2) return method2;
....
}
 
Joseph Siao
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks again.

value1, value2, and value3 will be coming from a modal dialog. Its values are yes, no and cancel.

depending on the value, different methods are called from a single button. is this possible? or is there a different approach?
 
Joseph Siao
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Lynette.

I can do that. but the values are coming from the jsp page. or is there a way to pass a parameter through the action? something like this:

h:commandButton action="#{myBean.method(parameter)}"
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
see http://balusc.xs4all.nl/srv/dev-jep-com.html
 
Joseph Siao
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Lynette. This will help greatly.
 
Joseph Siao
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lynette. I tried the website you gave me.

I used attribute on my commandButton to pass values. I have a new error, attribute does not support runtime expressions.

Here is how I did it:

h:attribute param="response" value="<%=resp;%>"

any way around this?
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Put it in the sessionMap or requestMap using JSP. And then retrieve the value from FacesContext.getCurrentInstance().getExternalContext().getSessionMap() or .getRequestMap().
 
Joseph Siao
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bauke. I'll give it a try.
 
reply
    Bookmark Topic Watch Topic
  • New Topic