voyent
Problem with a combination of c:forEach and ace:menuItem  XML
Forum Index -> Portals & Portlets
Author Message
magruene

Joined: 20/Mar/2012 07:42:17
Messages: 18
Offline


Hello everybody,

it's been some time since I last posted something on here, so please don't blame me, if I violate any forum regulations =).

Ok, so I'm developing a Portlet using Icefaces (3.0.1) and I'm facing a wierd problem with the forEach X menuItem combination.

The code-snipped in question:

Code:
<ace:menuButton value="#{i18n['transitions']}">
 				<c:forEach items="${transitionBean.possibleTransitions}" var="transition">
 					<ace:menuItem value="#{transition}"
 						action="#{transitionBean.updateIssueWithTransition}">
 						<f:param name="selectedTransition"
 							value="#{transition}" />
 					</ace:menuItem>
 				</c:forEach>
 			</ace:menuButton>


What I'm trying to do is to fill a List (possibleTransitions) with String values and then create an MenuItem for each String value for it to be displayed and clickable. When clicked, the Page should put the "selectedTransition" param in the request for me to read back in the bean. However, although the values are correctly displayed and the menuItems are added, nothing happens when I click one of the menuItems. My method is never fired. Fun thing is, if I add a ArrayList manually and assign it to c:forEach everything works like expected. Hoewever if I try to add the initial possibleTransitions list to the test List, the manually added String work but the "possibleTransitions"-Part still won't work.

Code in the backing Bean:Code:
 
 	public List<String> getPossibleTransitions() {
 		if (possibleTransitions.size() == 0 && incidentBean != null
 				&& incidentBean.getCurrentIssue() != null) {
 			possibleTransitions = incidentBean.getJiraServiceRest()
 					.getPossibleTransitionsWithJson(
 							incidentBean.getCurrentIssue().getIssueKey());
 			for (String string : possibleTransitions) {
 				System.out.println(string + " from getMethod");
 			}
 		}


Also the one with "test list":
Code:
 public List<String> getTestList() {
 		testList.clear();
 		testList.add("test 1");
 		testList.add("test 2");
 		if (incidentBean != null && incidentBean.getCurrentIssue() != null) {
 			testList.addAll(incidentBean.getJiraServiceRest()
 					.getPossibleTransitionsWithJson(
 							incidentBean.getCurrentIssue().getIssueKey()));
 		}
 
 		return testList;
 	}


As said before, the manual part of the testList works, the part with the addAll-Method doesn't or at least the MenuItems are created with the correct String values but the action is not fired for those.

I checked with firebug, whether I can figure out a difference between the two elements but there doesn't seem to be one. Now I tried pretty much everything and I can't figure out what's the problem.

I really hope you can help.

Thanks in advance!

Cheers

Marc


P.S. I added a screenshot showing the firebug output, maybe it helps..


[Thumb - portlet.png]
 Filename portlet.png [Disk] Download
 Description
 Filesize 47 Kbytes
 Downloaded:  1126 time(s)

dsinotte

Joined: 14/Nov/2006 00:00:00
Messages: 33
Offline


What scope is the bean?

Does the same issue occur in a non-portlet environment (that is, if you take the same markup and bean code and just run it in Tomcat, does it behave differently)? Just trying to see if it's portlet specific.

Is it possible to replace c:forEach with ui:repeat?
magruene

Joined: 20/Mar/2012 07:42:17
Messages: 18
Offline


dsinotte wrote:
What scope is the bean?

Does the same issue occur in a non-portlet environment (that is, if you take the same markup and bean code and just run it in Tomcat, does it behave differently)? Just trying to see if it's portlet specific.

Is it possible to replace c:forEach with ui:repeat? 



Hey, sorry for the late reply, for some reason I haven't received a notification mail. I just checked back, to post, that I got it resolved.

It was a completely diffrerent issue though. Because I'm using <ui:include> to build up my UI, the ViewScope for some reason fails to build up correctly and will get reinstanciated on every request, much like a RequestScoped Bean. For reference: http://balusc.blogspot.de/2011/09/communication-in-jsf-20.html#ViewScopedFailsInTagHandlers

Adding the following to the web.xml resolved this:

Code:
     <context-param>
         <param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
         <param-value>false</param-value>
     </context-param>


Also, to answer your other question. <ui:repeat> didn't work, because I got a ClassCastException when combining <ace:menuItem> and <ui:repeat>.

However, now that it works, I seem to have a diffrerent problem. After the submit is successfull, the <ace:menu> (I changed it to that from <ace:menuButton> for design reasons) renders somewhat broken. (Image attached). Is there anything I can do? (I checked with menuButton too, the same thing happens)

Cheers

Marc
[Thumb - Menu_broken.png]
 Filename Menu_broken.png [Disk] Download
 Description
 Filesize 9 Kbytes
 Downloaded:  1118 time(s)

dsinotte

Joined: 14/Nov/2006 00:00:00
Messages: 33
Offline


I recently added a comment about some of the issues of using ViewScoped beans to our Wiki that might be useful. Look for the special note under the section about changing bean scopes:

http://www.icesoft.org/wiki/display/ICE/Converting+ICEfaces+1.8+Applications+to+ICEfaces+3

This behaviour may have been fixed in a very recent release of Mojarra so you could try upgrading to see if it helps. I mention this because setting PartialStateSaving to false may have it's own problems:

http://java.net/jira/browse/JAVASERVERFACES-2636

Can you post the most markup code for the ace:menu issue?
magruene

Joined: 20/Mar/2012 07:42:17
Messages: 18
Offline


Hello again, I updated Mojarra and I can remove the PartialStateSaving context-param. Thanks. However the display issue remains. I'm not exactly sure what you mean with markup code as it seems my english skills only go that far, but I'll try and provide a little more details.

I have a xhtml-page which displays details from a JIRA Issue fetched via REST. On the page I'm able to edit the fields and update the issue, again via REST. Also I added the possibility to change the current stauts of the Issue via the Transitions. The possible Transitions are displayed in the ace:menu tag dynamically:

Code:
<ace:menu model="#{transitionBean.menuModel}" type="tiered" id="transition_menu_model">
 				<!-- <c:forEach items="${transitionBean.possibleTransitions}" var="transition">
 					<ace:menuItem value="#{transition.key}"
 						actionListener="#{transitionBean.updateIssueWithTransition}">
 						<f:param name="selectedTransition"
 							value="#{transition.value}" />
 					</ace:menuItem>
 				</c:forEach> -->
 			</ace:menu>


Notice that I commented the c:forEach part for now, as I'm currently using the "model"-attribute to build the menu dynamically:

Code:
public DefaultMenuModel getMenuModel() {
 		menuModel = new DefaultMenuModel();
 		Submenu subMenu = new Submenu();
 		subMenu.setId("transition_subMenu");
 		subMenu.setLabel(ResourceBundle.getProperty("transitions"));
 		menuModel.addSubmenu(subMenu);
 		for (Entry<String, Integer> entry : getPossibleTransitions().entrySet()) {
 			MenuItem menuItem = new MenuItem();
 			UIParameter uiParam = new UIParameter();
 			uiParam.setName("selectedTransition");
 			uiParam.setValue(entry.getValue());
 			menuItem.setId(entry.getKey().replaceAll(" ", "_").toLowerCase() + "_" + entry.getValue().toString());
 			menuItem.getChildren().add(uiParam);
 			menuItem.setValue(entry.getKey());
 			menuItem.setAction(LiferayFacesContext
 					.getCurrentInstance()
 					.getApplication()
 					.createMethodBinding("#{transitionBean.updateIssueWithTransition}",
 							new Class[] {}));
 			subMenu.getChildren().add(menuItem);
 		}


I'm aware that "setAction" is deprecated, I may change that later. Everything displays correctly and works fine until I press one of the menuItems and submit a transition. After the update is finished, I reload the current Issue to display the new values on the page. The users stays on the same page after the update process is finished. It works if I leave the current page after the update and manually go back to the detail page after that, however that is bothersome and not what I intended.

Cheers

Marc
artzambrano

Joined: 21/Mar/2007 00:00:00
Messages: 175
Offline


The menu component is designed to work in a more asynchronous way, making dynamic updates on the same page as you activate menu items (unless the menu item has a 'url' attribute). If you want to move to a different page, perhaps you could try adding an actionListener method to the menu item, and from there redirect the user manually to a different page/url.


Art Zambrano
ICEsoft Technologies Inc.
magruene

Joined: 20/Mar/2012 07:42:17
Messages: 18
Offline


artzambrano wrote:
The menu component is designed to work in a more asynchronous way, making dynamic updates on the same page as you activate menu items (unless the menu item has a 'url' attribute). If you want to move to a different page, perhaps you could try adding an actionListener method to the menu item, and from there redirect the user manually to a different page/url.

 


Thanks for the reply but I do want to stay on the same page. The problem is, that the menu is rendered/displayed wrong, after I clicked on a menuItem. (See screenshot a few posts above)

Cheers

Marc
artzambrano

Joined: 21/Mar/2007 00:00:00
Messages: 175
Offline


I see. Well, that was a styling issue that was fixed in 3.1 or 3.2. What happens is that the <ul> element that defines the menu is updated dynamically, without re-initializing the component, thus the styling is not re-applied in the client. If you update to the latest version of ICEfaces, you won't have that problem.

Art Zambrano
ICEsoft Technologies Inc.
magruene

Joined: 20/Mar/2012 07:42:17
Messages: 18
Offline


Indeed. Updating to 3.2 helped. Thank you both very much.

Cheers Marc
 
Forum Index -> Portals & Portlets
Go to:   
Powered by JForum 2.1.7ice © JForum Team