I have a JSF application where I need to create almost all of the UIComponents dynamically based on certain parameters to the page. The components are created and added to an HtmlPanelGrid. I've been successfully creating HtmlLabel, HtmlInputText, UISelectBoolean, and HtmlCommandButton. Now I need to create an HtmlSelectOneMenu and add it, and I'm having a hard time finding examples that show how to attach the list of items to select.
The selection list is this, where I've made cfaItems a property of my backing bean:
SelectItem[] cfaItems = {
new SelectItem(1, "1"),
new SelectItem(2, "2"),
new SelectItem(3, "3"),
new SelectItem(4, "4"),
new SelectItem(5, "5")
};
The creation of the HtmlSelectOneMenu:
HtmlSelectOneMenu cfaMenu = (HtmlSelectOneMenu)
getApplication().createComponent(HtmlSelectOneMenu.COMPONENT_TYPE);
cfaMenu.setId("cfaMenu");
grid.getChildren().add(cfaMenu);
As best as I can figure it out, I need to create a ValueExpression that would bind the cfaItems list to the cfaMenu but not finding any examples is a problem. I think that I need to do something like this
String menuBinding =
"#{" + beanName + ".cfaItems}";
ValueExpression menuVE = getApplication().getExpressionFactory().
createValueExpression(FacesContext.getCurrentInstance().
getELContext(), menuBinding, String.class);
cfaMenu.setValueExpression("value", menuVE);
But I don't think that's correct. Any suggestions?
You need to create an UISelectItems instance with the given select item array as value and then add it as child of the menu, exactly as you'd do with <f:selectItems> in the view side.
UISelectItems selectItems = new UISelectItems();
selectItems.setValue(cfaItems);
cfaMenu.getChildren().add(selectItems);
Related
I am developing a master detail Fiori app using SAP UI5. As the details contains more than 40 columns, I made separate OData services for master & detail.
In Master page, data are coming correctly. Now my task is that on any table line, when user clicks on Detail, next page will be open with details base on two key values of master table.
I'm getting two keys in variables in detail page as follows and it is working fine:
var spayid = jQuery.sap.getUriParameters().get("payid");
var spaydt = jQuery.sap.getUriParameters().get("paydt");
Next, I have created two filters as follows which is also working fine.
var filter1 = new Filter({
path: "Laufi",
operator: FilterOperator.EQ,
value1: spayid
});
var filter2 = new Filter({
path: "Laufd",
operator: FilterOperator.EQ,
value1: spaydt
});
Now I am calling OData service which is also working fine:
var oODataModel = new ODataModel("proxy/http/FIORI-DEV.abc.com:8000/sap/opu/odata/sap/ZASA_FI_pay_D_SRV?sap-client=100", {
json: true,
useBatch: false
});
this.getView().setModel(oODataModel);
I don't know now how to filter data. What should be included in above so that it will filter data according to my filters filer1 and filter2? I have tried following but it is not working.
filters : [ filter1, filter2 ],
json: true,
useBatch: false
I am very good in ABAP but not an expert in SAPUI5. I am in learning phase.
First of all, I was thinking to pass parameters on OData service so that only the required data are fetched. Means my OData call should be like this:
new ODataModel("proxy/http/FIORI-DEV.abc.com:8000/sap/opu/odata/sap/ZASA_FI_PAYMENT_D_SRV/PdetailSet(Laufi= spayid, Laufd = spaydt)?sap-client=100");
But this seems not like possible.
Second option is that I will fetch whole details in OData service and then during binding to table I will apply filter.
The purpose of the sap.ui.model.Filter class is usually to apply filters to lists on the UI. For example, if you have a list of items and you want to limit that list to a subset of items which fulfills certain criteria.
But what you have here appears to be a classic master-detail scenario where you have a list of items and then when the user selects one show more information about that one item.
The usual solution for such a scenario is to assign the full model to the detail-view and then use an element binding (also known as "context binding") on the view to tell it which item to display.
When the source of the item is a click on an element which already had an element binding, then you can actually retrieve the correct binding path from the click event and just apply it to your detail-view.
From one of the official demos:
onItemSelected: function(oEvent) {
var oSelectedItem = oEvent.getSource();
var oContext = oSelectedItem.getBindingContext("products");
var sPath = oContext.getPath();
var oProductDetailPanel = this.byId("productDetailsPanel");
oProductDetailPanel.bindElement({ path: sPath, model: "products" });
}
When you don't have any convenient way to get an element path from, then you have to construct one yourself:
var detailPanel = this.getView().byId("idOfDetailPanel");
detailPanel.bindElement("PdetailSet(Laufi = " + spayid +", Laufd = " + spaydt + ")");
The latter code snippet does of course assume that the oData-service actually supports access with a key consisting of laufi and laufd. This is decided by:
The definition of the key fields of the entity type in the SAP Gateway Service Builder (transaction SEGW)
The ABAP implementation of the method get_entity of the data provider class of that oData-service.
I have a combo box that I am trying to add options to. How Do I go about this? This is what I have so far:
ComboBox contactPrefixNametf = new ComboBox("Prefix");
contactPrefixNametf.setItemCaption(contactPrefixNametf, "Mr");
fLayout.addComponent(contactPrefixNametf);
contactPrefixNametf.setImmediate(true);
I guess .setItemCaption() is not the correct method? What is the correct method?
Thank you in advance!
Use addItem() method:
final ComboBox my_combox_box = new ComboBox("My Combo Box");
for (final My_object mo: list_of_my_objects)
{
my_combox_box.addItem(mo);
my_combox_box.setItemCaption(mo, mo.name());
}
This example uses addItem inconjunction with setItemCaption() to store the actual object selected by the user with a display friendly name (if toString() is not appropriate).
myComboBox.addItem("Option 1");
(Especially if you are new to Vaadin), I suggest to try Viritin add-on and its TypedSelect variant of ComboBox. Its well typed API makes many things ridiculously simpler. For instance it has a (typed) setOptions method and its value change listeners provide the value directly instead of through untyped Property interface.
A code example of its usage:
List<Person> options = service.findMyPersons();
TypedSelect<Person> select = new TypedSelect<>(Person.class)
.withSelectType(ComboBox.class);
select.setOptions(options);
// If toString() representation is not good, modify it to something else
select.setCaptionGenerator(person -> person.getFirstName() + person.getLastName());
select.addMValueChangeListener(event -> {
Person person = event.getValue();
});
Disclaimer: I'm the maintainer of Viritin, but also have maintained Vaadin for 8 years and nowadays work as its developer advocate.
I'm doing some custom infrastructure for auto-generating specific bundles for individual views, and have a case where I need to get the Layout value for each view while iterating them as files.
I've tried var view = new RazorView(new ControllerContext(), actionView.FullName, null, true, null); but this is taking the LayoutPath as an input, and it is indeed resulting in an empty string on the LayoutPath property of the RazorView if I give null for that parameter, so it's not parsing the file for the value.
Could there be any other way to solve this in a similar manner, or would my best/only option be to just parse the text of the raw file (and _ViewStart)?
This is only done once at application start, so the performance is currently not an issue.
Alright, after a lot of source debugging and an epic battle with the internal access modifier, I have a working solution without having to render the whole page. I don't expect anyone else ever having the need for this, but anyway:
var httpContext = new HttpContextWrapper(new HttpContext(new HttpRequest("", "http://dummyurl", ""), new HttpResponse(new StreamWriter(new MemoryStream()))));
var page = Activator.CreateInstance(BuildManager.GetCompiledType(ReverseMapPath(actionView.FullName))) as WebViewPage;
page.Context = httpContext;
page.PushContext(new WebPageContext(), new StreamWriter(new MemoryStream()));
page.Execute();
var layoutFileFullName = page.Layout;
// If page does not have a Layout defined, search for _ViewStart
if (string.IsNullOrEmpty(layoutFileFullName))
{
page.VirtualPath = ReverseMapPath(actionView.FullName);
var startpage = StartPage.GetStartPage(page, "_ViewStart", new string[] {"cshtml"});
startpage.Execute();
layoutFileFullName = startpage.Layout;
}
Tada!
Ps. ReverseMapPath is a any arbitrary function to resolve the relative path of a full file name, see for example Getting relative virtual path from physical path
I have create a selectOtherItem in my SmartGWT .
i have just shifted from GWT where we simply do
listBox.addItem("some Item");
and to put the values coming from a loop and also to save the id against every item (for values coming from db)
for(int i =0;i <list.size; i++){
listBox.addItem(list.getName(i), list.getId(i));
}
but i'm not able to do these stuff in smartGWT .
Now i am using selectOtherItem .
If you can please guide how i can do the same thing in smartGWT, which i have show above.
thanks
SmartGWT also has the same functionality. You can directly add the Strings to a ComboBoxItem or SelectItem as mentioned below:
comboboxItem.setValueMap("s", "a", "d");
OR you can also prepare a LinkedHashMap, to specify key-value pair as mentioned below:
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
for (Obj obj : objList) {
map.put(String.valueOf(obj.getId()), obj.getName());
}
comboboxItem.setValueMap(map);
Besides, you can also fill up a ComboBoxItem or SelectItem using a DataSource.
For further details, refer this link.
i'm working on a symfony project to manage a database. First i explain how it works:
In the database, all elements are associated to an unique element 'scene'. When a user accesses the application, chooses what scene he wants to see (it saves that in a user parameter). So when listing elements, the application should only list elements associated with the scene selected by the user.
*Note: all elements have an scene attribute in the table definition.
So my problem comes here:
I developed a listing of an element entities using the help of a sfPropelPager class to paginate. Also added some filters to search in the list, and for that i used the filter system provided by symfony (<element>FormFilter.class.php and stuff).
Now i want the list to not show elements from other scenes than the selected by the user.
How can i do to add additional criteria to the criteria given by the filter class?
or How would you solve the problem?
here is my action code:
public function executeUnidadfilter(sfWebRequest $request){
$this->filter = new BaUnidadorganizativaTblFormFilter();
$c = $this->filter->getCriteria();
$this->filter->bind($request->getParameter($this->filter->getName()));
if($this->filter->isValid()){
$this->pager = new sfPropelPager('BaUnidadorganizativaTbl',$this->sfPropelPagerLines);
echo $this->getUser()->getEscenario();
$this->pager->setCriteria($c);
$this->pager->init();
}else{
$this->pager = new sfPropelPager('BaUnidadorganizativaTbl',$this->sfPropelPagerLines);
$this->pager->init();
}
$this->setTemplate('Unidadlist');
}
*Note: 'scene' mentioned below is Escenario in the code
thank you very much for your time
I solved the problem. The trouble was that i assigned the formfilter generated criteria to my criteria var Before the filter was filled. That's why of the error.
The resulting code is that:
public function executeUnidadfilter(sfWebRequest $request){
$this->filter = new BaUnidadorganizativaTblFormFilter();
$this->filter->bind($request->getParameter($this->filter->getName()));
if($this->filter->isValid()){
$this->pager = new sfPropelPager('BaUnidadorganizativaTbl',$this->sfPropelPagerLines);
$esc = $this->getUser()->getEscenario();
$c = new Criteria();
$c = $this->filter->getCriteria();
$c->addAnd('codigo_escenario',$esc);
$this->pager->setCriteria($c);
$this->pager->init();
}else{
$this->pager = new sfPropelPager('BaUnidadorganizativaTbl',$this->sfPropelPagerLines);
$this->pager->setCriteria($this->filter->getCriteria());
$this->pager->init();
}
$this->message=null;
$this->messageType=null;
$this->setTemplate('Unidadlist');
}