I am creating a dropdown in XUL like this:
<button id="bid" oncommand="alert(event.target.nodeName)" >
<menupopup>
<menuitem label="one" value="one" />
<menuitem label="two" value="two" />
<menuitem label="three" value="three" />
</menupopup>
</button>
I want to alert the value of nodeitem which is being clicked. Using event.target.nodeName giving nodeName as menuitem but using nodeValue is retuning undefined as it starts to take value of button node. How can I get the value of the menuitem clicked. I also tried $(this).val() but even that gave undefined. Using $(this).attr('value')
also didn't help. I can put oncommand for menuitem but that doesn't seem to be actual solution. Is that the only way or some method exist to get the value?
The XUL code you have in the question is non-functional. Either you should be using a <menulist> instead of a <button>, or your <button> needs the property type="menu" or type="menu-button". If you are going to use a <button> without the type="menu" property, you would actually have to open a popup in the command event handler for the <button> and then select from there. That does not appear to be what you are wanting. It is, however, quite doable. I use a construction like that in one of my add-ons, except I have it open when one of several <label> items is clicked. This allows re-use of a single <menupopup> for multiple different items in the window. In that case, the <menupopup> is a rather large amount XUL code that I did not want to repeat and maintain multiple duplicates in the XUL for the window.
The value of the <menuitem> selected:
Your actual question is how to get the value of the <menuitem> selected by the user. All of the code below is tested and functional. As you can see from the code you can get the value of the <menuitem> you select (at the time of selection) from: event.target.value.
Using a <menulist> element:
The most common element to use would be a <menulist>. This would normally be used when you are having the user select from multiple options a choice that is going to be remembered and used later, or used to adjust what is presented in the user interface. It would generally not be used to select from multiple immediate actions (which are acted upon and the choice not remembered). A <menulist> is what is used in the examples for <menuitem> and <menupopup> on MDN.
<menulist id="bid2" oncommand="alert(event.target.value)" >
<menupopup>
<menuitem label="one" value="one" />
<menuitem label="two" value="two" />
<menuitem label="three" value="three" />
</menupopup>
</menulist>
The above code will give you what looks like a button with a selection of <menuitem> entries when you click on it. It will alert with the value of the <menuitem> you have selected.
This will produce an item that looks like:
Which you can click on to open a drop-down list:
If you select an item:
You will get an alert:
And the object will then show your selection:
Using a <button> element:
It is also possible to use a <button> element with the property type="menu" or type="menu-button" specified. However, this provides no visual feedback to the user as to which option is currently selected. [Note: Your JavaScript could manually change the <button> label property to provide this feedback.] You could use this type of element if it is button that produces an immediate action rather than a selection that is remembered.
The code:
<button type="menu" id="bid2" label="A Button" oncommand="alert(event.target.value)">
<menupopup>
<menuitem label="one" value="one" />
<menuitem label="two" value="two" />
<menuitem label="three" value="three" />
</menupopup>
</button>
This will produce an item that looks like:
Which you can click on to open a drop-down list:
If you select an item:
You will get an alert:
And the object will then NOT show your selection:
If you want to set the label of the <button> to reflect the selection made by the user, you could use:
<button type="menu" id="bid2" label="A Button" oncommand="event.target.parentElement.parentElement.label=event.target.value;alert(event.target.value)">
<menupopup>
<menuitem label="one" value="one" />
<menuitem label="two" value="two" />
<menuitem label="three" value="three" />
</menupopup>
</button>
When three is selected, that will result in a button that looks like:
Using a <toolbarbutton>:
You could, alternately, use a <toolbarbutton>.
When not hovered, doing so would look like:
When hovered:
When open for selection:
Choices in UI design:
There are many choices that you have to make when designing your user interface. There are many different ways to get to the same effective result, with somewhat different look and feel. You really should be trying these types of options on your own. You may find the XULRunner program XUL Explorer to be of use when prototyping XUL.
Selecting UI elements and a look and feel is, in my opinion, beyond the scope of questions on stackoverflow. While you probably won't get specific XUL help, you can ask UI design questions at: the User Experience stack exchange.
Related
I got a simple login form. I am using <p:ajax> to invoke a <p:blockUI> (see this question).
<h:commandButton id="anmeldung_button"
action="#{benutzerAnmeldung.anmelden}" value="Anmelden"
styleClass="btn btn-info btn-sm">
<p:ajax process="#form" update="#form"/>
</h:commandButton>
<p:blockUI id="block" block=":anmeldung" trigger="anmeldung_button" />
I am using <o:highlight /> to highlight invalid inputs. This works fine.
It is working with a <f:ajax> perfectly, too.
Apperently, it is not working with <p:ajax>.
How can I achieve this?
This is caused by <p:ajax> trying to refocus the active element after executing the oncomplete scripts via doEval() (as can be seen in handleReFocus() function in core.ajax.js script. However, when you submit the form by clicking the command button instead of pressing Enter while inside the input, then that active element becomes the command button itself, not the input text. You can confirm this by just using Enter key to submit the form. You'll see that the focus is done right.
There are in your particular case 2 ways to workaround this:
Make use of PrimeFaces' own autofocus facility via <p:focus> which is placed inside the form as below:
<h:form id="anmeldung">
<p:focus context="anmeldung" />
...
</h:form>
It also automatically takes into account invalidated input fields.
Set PrimeFaces.customFocus to true in JavaScript, so that handleReFocus() function won't do its job.
<script>PrimeFaces.customFocus = true;</script>
I need to refresh page in include tag, but this is load dynamically using forEach property, this is a fragment of my code:
<button onClick="... refresh include page ..."/>
<tabbox id="tb" orient="vertical" >
<tabs>
<tab forEach="${vm.columnList}" label="${each}" hflex="true"/>
</tabs>
<tabpanels>
<tabpanel forEach="${vm.columnList}" >
<include height="90%" rc="/Campaigns.zul" rca="${each}" date="${vm.date}" />
</tabpanel>
</tabpanels>
</tabbox>
I want that when the button is pressed, the page that is in the include will reload, not whole page. Try using an id to use invalidate function, but using the forEach property to load the page gave an error with repeated id.
The page is loaded using forEach because depending of the parameter that is passed the content is different and different tabs are generated.
In the onClick of the button try this
<button onClick="tb.getSelectedPanel().getFirstChild().invalidate()" />
I have following structure to display in zul file and got List of clinic object from Java controller.
I tried several zk components in zul with no luck. What component should I use with a forEach?
ListBox
ListItem
Grid
Here is structure need to display :
For each clinic
{
For each clinic.location
{
For each (clinic.location.provider)
{
Output (provider display name)
}
Output (clinic name)
Output (clinic.location address)
Output (clinic.locatoin telephone number)
Output (clinic.web address)
}
}
As explained in the answer given by Darius, here is an example of how to use a <Grid> with a <rows> component
<?page title="Result"?>
<zk>
<window apply="org.zkoss.bind.BindComposer"
viewModel="#id('vm') #init('fully.qualified.viewmodel.classname')"
title="Result Window" border="normal" >
<div>
<grid>
<rows>
<row>
<listbox model="#bind(vm.listname)">
<listhead>
<listheader label="Item Name"
style="text-align:center;">
</listheader>
<listheader label="Attribute Value"
style="text-align:center;">
</listheader>
<listheader label="Qualifier Value"
style="text-align:center;">
</listheader>
</listhead>
<template name="model" var="item">
<listitem value="${item }">
<listcell label="#load(item.name)"
style="text-align:center;">
</listcell>
<listcell
style="text-align:center;">
<textbox
value="#bind(item.attributeValue)"
style="text-align:center;" />
</listcell>
<listcell
label="#load(item.qualifierValue)"
style="text-align:center;">
</listcell>
</listitem>
</template>
</listbox>
</row>
</rows>
</grid>
</div>
</window>
</zk>
You can use a Listbox or a Grid.
If you use a Listbox, it will contain Listitem objects
If you use a Grid, it will contain a Rows object, which will contain Row objects
To the Listitem or the Row, you will add other components: the simplest would be Label objects
I notice you have an inner table of providers. For these, you will probably need a nested Grid or Listbox. You could also use ZK's Detail component. it would allow you to expand in order to see the inner table.
There are multiple ways how to achieve this
including separate zul file to template row, whitch will contain a grid with separate view model - this style you can have shown all nested grid at once ,but it should and it will have performance issiues with larger ammout of data(because count of rows == count of viewmodels of nested grids)
include nested grid with own template ,and data model as parameter of view model,and show this grid on demand(button click,row click etc) - this is bether way in case of no performance issues,but you will be able to show only one nested grid at time
Final words - just don´t
Nesting a grid to grid is a very bad design,because it is incredibly hard to render this,and it is only usable for small data. The best way to do this,in my opinion is to create two separate grids,side by side,and show adition data on in second grid,after a click on row in first grid. This way you can achieve very fast gui with no performance issiues,ever with a lot of data. Another way is to create a popup on grid row,whitch will show additional data,a it is also a lot bether for your performance.
I successfully created tables with style that salesforce provided. (like the one that highlighted on mouseover etc)
But I want the value of column to be a link to display detail info of the object.
When I don't create my own visualforce page, the table looks nice and the column
values (records) are all hyperlinked but can't figure out how to do it from visualforce apex code.
pageBlockTable and column definition does not seem to have attributes or anything that
make it hyperlink.
http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_pageBlockTable.htm
http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_column.htm
<apex:pageBlock title="test">
<apex:pageBlockTable value="{!workObj}" var="item">
<!-- below needs to be hyperlink -->
<apex:column value="{!item.name}" />
</apex:pageBlockTable>
</apex:pageBlock>
I could achieve my goal by throwing the good design away like below but I would like to keep the code above.
This works but no salesforce style is applied.
<apex:pageBlock title="my test title" >
<apex:dataTable value="{!workObj}" var="wn" cellpadding="2" cellspacing="2">
<apex:column>
<apex:facet name="header">仕事名一覧</apex:facet>
<apex:form >
<apex:commandLink value="{!wn.name}" />
</apex:form>
</apex:column>
</apex:dataTable>
</apex:pageBlock>
Instead of <apex:column value="{!item.name}" />, try doing it like this in the column body:
<apex:pageBlock title="test">
<apex:pageBlockTable value="{!workObj}" var="item">
<apex:column>
<apex:outputLink value="{!item.name}">{!item.name}</apex:outputLink>
</apex:column>
<apex:pageBlock title="test">
<apex:pageBlockTable value="{!workObj}" var="item">
I have a listbox in markup and a detail control. The listbox template defines a details button for each element. If this button is pressed a dependency property in the element's datasource is set to Visiblility == Visible. As long as I do have a selected item everything is OK. But if there is no selected item, the detail control is displayed always. Markup:
<Listbox x:Name="myListbox" />
<local:detailcontrol Visibility="{Binding ElementName=myListbox, Path=SelectedItem.DetailVisibility}" />
What I want is something like this:
<Listbox x:Name="myListbox" />
<local:detailcontrol Visibility="myListbox.SelectedItem != null ? {Binding ElementName=myListbox, Path=SelectedItem.DetailVisibility} : Visiblity.Hidden" />
Snippets both do not compile, but are provided to make my point clear.
Starting using the article at http://www.11011.net/wpf-binding-expressions I implemented something similar which solved my problem