How to show JSF 1.2 selectonemenu with selected values from a list - jsf-1.2

I am using jsf 1.2 selectonemenu, i have a requirement that when the page loads with the selectonemenu will load some data from database and a value will be selected in the listbox.i have done it using hardcode values.But When it is coming from DB it is not working, i am posting both my hardcode and db coding.
<h:selectOneMenu id="submenu" value="three">
<f:selectItem id="si1" itemLabel="One" itemValue="one" />
<f:selectItem id="si2" itemLabel="Two" itemValue="two" />
<f:selectItem id="si3" itemLabel="Three" itemValue="three" />
<f:selectItem id="si4" itemLabel="Four" itemValue="four" />
</h:selectOneMenu>
DB Coding
<h:selectOneMenu id="submenu">
<f:selectItem id="si1" itemValue="${useBean.memberDependentList}" />
</h:selectOneMenu>
My Bean class
List<DependentDTO> dependentList = new MemberProxy()
.getDependentListFormMember( loggedInUser
.getUserAccessList().get(0).getClientCode(),
loggedInUser
.getUserAccessList().get(0).getCertificateNumber());
List<SelectItem> selList=new ArrayList<SelectItem>();
for(DependentDTO depDTO:dependentList){
SelectItem sel = new SelectItem();
sel.setLabel(depDTO.getNameFirst());
sel.setValue(depDTO.getCertNumber()+"#"+depDTO.getClientCode()+"#"+depDTO.getDependentCode());
selList.add(sel);
}
mem = new MemberProxy().getMemberDetails(loggedInUser
.getUserAccessList().get(0).getClientCode(), loggedInUser
.getUserAccessList().get(0).getCertificateNumber());
SelectItem sel = new SelectItem();
sel.setLabel(mem.getNameFirst());
sel.setValue(mem.getCertNumber().toString().trim()+"#"+mem.getClientCode().toString().trim()+"#"+depDTO.getDependentCode());
selList.add(sel);
memberDependent.setMemberDependentList(selList);
I am setting the person name in the label and the value i am setting the certificate number ,client code and dependent code ,here the dependent code is unique.Certificate number and client code are same in both cases.Can i do something with the dependent code? when the list is populating in the dropdown. Because my purpose is to show always the mem.getNameFirst() selected when page is loaded.Is it possible with any tricks???Please help i am new to JSF 1.2
How i will show three as selected when loding data from database

You should use value from bean:
<h:outputText value="Country: " />
<h:selectOneMenu id="countries" value="#{bean.country}">
<f:selectItems value="#{bean.countries}" />
</h:selectOneMenu>

Related

Use an h:commandButton to toggle rich:dataScroller

Has anyone used a commandButton to toggle a rich:dataScroller on and off? Would I need to make a bean to keep track of if the rich:dataScroller is active or not and make the action of the commandButton to toggle the bean?
What do you mean by on/off? Does it means show/hide? If so, you can do something like this.
Assume that you have following table which has a datascroller and a commandButton below the table.
<h:form>
<rich:dataTable var="_usr" value="#{myBean.users}" rows="5">
<rich:column>
#{_usr.userName}
</rich:column>
<f:facet name="footer">
<rich:datascroller id="myScroller" />
</f:facet>
</rich:dataTable>
<a4j:commandButton value="Show/Hide" onclick="toggleScroller(#{rich:element('myScroller')});"/>
</h:form>
The javascript function which shows/hides the datascroller is as below.
<script>
function toggleScroller(scroller) {
if(scroller.style.display == 'none') {
scroller.style.display = ''
} else {
scroller.style.display = 'none'
}
}
</script>
Or you can use the rendered property of the <rich:datascroller> to render it according to a bean property.

CRM2011 subgrid button enable rule

I have 2 issues.
First issue: Trying to hide OOB button in subgrid(Ribbon), based on user role(by calling javascript). Is it possible?
Second issue: Hiding OOB button is not possible through "enablerule"javascript, so alternative I tried to disable button by using "enablerule"/javascript. Here is following code which reflects above. Still is NOT working, but for main form Ribbon button, the below code is working.
Can anyone please help me?
<Groups Id="Mscrm.SubGrid.quote.MainTab.Groups">
<Group Id="Mscrm.SubGrid.quote.MainTab.Management" Command="Mscrm.Enabled" Sequence="10" Title="$Resources:Ribbon.HomepageGrid.MainTab.Management" Description="$Resources:Ribbon.HomepageGrid.MainTab.Management" Image32by32Popup="/_imgs/ribbon/newrecord32.png" Template="Mscrm.Templates.Flexible2">
<Controls Id="Mscrm.SubGrid.quote.MainTab.Management.Controls">
<Button Id="Mscrm.SubGrid.quote.NewRecord" ToolTipTitle="$Resources(EntityDisplayName):Ribbon.SubGrid.MainTab.New" ToolTipDescription="$Resources(EntityDisplayName):Ribbon.Tooltip.New" Command="Mscrm.NewRecordFromGrid" Sequence="10" LabelText="$Resources(EntityDisplayName):Ribbon.SubGrid.MainTab.New" Image16by16="/_imgs/ribbon/NewRecord_16.png" Image32by32="/_imgs/ribbon/newrecord32.png" TemplateAlias="o1" />
<Button Id="Mscrm.SubGrid.quote.AddNewStandard" Command="Mscrm.AddNewRecordFromSubGridStandard" Sequence="20" LabelText="$Resources(EntityDisplayName):Ribbon.SubGrid.AddNew" Alt="$Resources(EntityDisplayName):Ribbon.SubGrid.AddNew" Image16by16="/_imgs/ribbon/NewRecord_16.png" Image32by32="/_imgs/ribbon/newrecord32.png" TemplateAlias="o1" ToolTipTitle="$Resources(EntityDisplayName):Mscrm_SubGrid_EntityLogicalName_MainTab_Management_AddNewStandard_ToolTipTitle" ToolTipDescription="$Resources(EntityDisplayName):Mscrm_SubGrid_EntityLogicalName_MainTab_Management_AddNewStandard_ToolTipDescription" />
</Controls>
</Group>
<CommandDefinitions>
<CommandDefinition Id="Mscrm.AddNewRecordFromSubGridStandard">
<EnableRules>
<EnableRule Id="new.quote.EnableRule2.EnableRule" />
</EnableRules>
<DisplayRules>
<DisplayRule Id="Mscrm.ShowForOneToManyGrids" />
<DisplayRule Id="Mscrm.AppendToPrimary" />
<DisplayRule Id="Mscrm.CreateSelectedEntityPermission" />
<DisplayRule Id="Mscrm.AppendSelected" />
<DisplayRule Id="Mscrm.HideAddNewForChildEntities" />
</DisplayRules>
<Actions>
<JavaScriptFunction FunctionName="Mscrm.GridRibbonActions.addNewFromSubGridStandard" Library="/_static/_common/scripts/RibbonActions.js">
<CrmParameter Value="SelectedEntityTypeCode" />
<CrmParameter Value="PrimaryEntityTypeCode" />
<CrmParameter Value="FirstPrimaryItemId" />
<CrmParameter Value="PrimaryControl" />
</JavaScriptFunction>
</Actions>
</CommandDefinition>
<EnableRule Id="new.quote.EnableRule2.EnableRule">
<CustomRule FunctionName="IsUserRoleAdmin" Library="$webresource:Quote_main_library.js" Default="false" InvertResult="true" />
</EnableRule>
//Javascript
function IsUserRoleAdmin()
{
var currentUserRoles = Xrm.Page.context.getUserRoles();
var isAdmin = false;
for (var i = 0; i < currentUserRoles.length; i++)
{
var userRole = currentUserRoles[i];
//check admin role
// if(userRole == "admin guid")
// {
// isAdmin = true;
// }
}
return isAdmin;
}
Yes you can hide or disable OOB buttons. This blog post provides some information.
Your js code is incorrect as Xrm.Page.context.getUserRoles() returns an array of GUIDs not the role names so isAdmin will always be false.
you can use Value Rule to Hide the Button on Ribbon..
to Disable you can use Custom Rule
check this link

Fill dropdown list from xml with linq

i have the following xml doc:
<?xml version="1.0" encoding="utf-8" ?>
<dropdowns>
<dropdown name="DropDownLoc">
<menu text="Select" value="-1" />
<menu text="North" value="1200" />
<menu text="South" value="1400" />
</dropdown>
<dropdown nome="DropDownEsp">
<menu text="Select" value="-1" />
<menu text="Est" value="7" />
<menu text="Ovest" value="9" />
</dropdown>
</dropdowns>
I want to read this xml and fill two dropdowns with a method given the dropdownlist name (like "DropDownEsp")
I want to accomplish this with linq, who can help me please ?
Below is code which would help you read XML and create a list of items (ListItem):
// or use XDocument.Parse("xml string") to parse string
XDocument xdoc = XDocument.Load(#"c:\testxml.xml");
var dropLists = xdoc.Descendants("dropdown")
.Select(d => d.Descendants("menu").Select(m =>
new /* new ListItem(text, value) */
{
Text = m.Attribute("text"),
Value = m.Attribute("value")
}))
.ToList();
Try adding items into controls yourself.
If you have an empty <asp:DropDownList ID="DynamicDropDown" runat="server" /> control on your .aspx page, you can data bind it a the results of a LINQ query like this:
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
// Assuming your XML file is in the App_Data folder in the root of your website
string path = Server.MapPath("~/App_Data/DropDowns.xml");
// Let's say we want to use the options from the second <dropdown>-tag in your XML
string whichDropDown = "DropDownEsp";
// This is the LINQ query to find those options from the XML
// and turn them into ListItem objects
var query =
from dropDown in XDocument.Load(path).Descendants("dropdown")
where dropDown.Attribute("name").Value == whichDropDown
from name in dropDown.Descendants("name")
let text = name.Attribute("text").value
let value = name.Attribute("value").value
select new ListItem(text, value);
// Now we data bind the query result to the control
DynamicDropDown.DataSource = query;
DynamicDropDown.DataBind();
}
}
In the LINQ query we first select only the <dropdown> element with the right name (based on the whichDropDown variable). Then we select all the <name> elements, and from each one we put the attributes in the text and value values. Then we use these values to create a new ListItem (one is created for each <name> element).
This result can then be used to data bind the <asp:DropDownList> control.

SL4 Binding problem with WCF RIA Services

Basic problem: How do I bind a textbox to the selected item of a combobox who's itemsource is the result of a LINQ query on a WCF RIA Services Domain context.
Additional requirement: When the selected item is changed the binding should update.
Additional requirement: The binding should be two way.
My solution so far:
After the user clicks to create a new item, new items are created and added to the object set but not persisted yet (one for each language). After that this code runs. The combobox is supposed to allow the user to select one of the created items, which is displayed as it's corresponding language. The bound textboxes should allow the user to edit the item.
Code behind:
//Setup the combobox
LanguageComboBox.ItemsSource = dc.GeneralStatistics.Where(g => g.RelatedResourceId.Equals(guid));
LanguageComboBox.DisplayMemberPath = "Language.LanguageName";
LanguageComboBox.SelectedItem = dc.GeneralStatistics.First(g => g.Language.LanguageName.Equals("English"));
//Setup the textboxes
this.StatisticsText.DataContext = (LanguageComboBox.SelectedItem as GeneralStatistics).Text;
this.ShortDescriptionText.DataContext = (LanguageComboBox.SelectedItem as GeneralStatistics).ShortDescription;
XAML CODE:
<ComboBox x:Name="LanguageComboBox" />
<TextBox x:Name="ShortDescriptionText" Text="{Binding}" />
<TextBox x:Name="StatisticsText" Text="{Binding}" />
The problem with my solution:
It does not work, because when I change the selection in the combobox the textboxes do not update. I could implement the selection changed event handler and manually update the textboxes, but that would defeat the purpose of binding the textboxes. What is the best practice here?
You can simplify the code by doing the following.
Code behind:
LanguageComboBox.DataContext = dc.GeneralStatistics.Where(g => g.RelatedResourceId.Equals(guid));
XAML:
<ComboBox x:Name="LanguageComboBox" />
<TextBox x:Name="ShortDescriptionText" Text="{Binding ElementName=LanguageComboBox, Path=SelectedItem.ShortDescription}" />
<TextBox x:Name="StatisticsText" Text="{Binding ElementName=LanguageComboBox, Path=SelectedItem.LongDescription}" />

How to modify how the custom field looks on sharepoint list (allitems view)?

I'm trying to write a custom field that is representing the time spend on the task. The field derives from NumberField (number is representing minutes) but I want to display it on the list as HH:MM for that purpose I've tried to override the fallowing function:
protected override void RenderFieldForDisplay(System.Web.UI.HtmlTextWriter output)
{
Label timeSpan = new Label();
timeSpan.Text = ((int)this.Value / 60).ToString() + ":" + ((int)this.Value % 60).ToString();
timeSpan.RenderControl(output);
//base.RenderFieldForDisplay(timeSpan.RenderControl());
}
I'm not an ASP.NET developer so I'm trying to avoid defining DisplayTemplate.
Can you show me the way how to render it programmatically or just push me in the right direction?
Solution
Solved with help from Kusek answer. In fldtypes_HourField.xml:
<RenderPattern Name="DisplayPattern">
<HTML><![CDATA[<div align='right'>]]></HTML>
<Switch>
<Expr>
<Column />
</Expr>
<Case Value="" />
<Default>
<HTML><![CDATA[<script src="/_layouts/hourField.js"></script>]]></HTML>
<HTML><![CDATA[<div><SCRIPT>formatHourField("]]></HTML>
<Column />
<HTML><![CDATA[");</SCRIPT></div>]]></HTML>
</Default>
</Switch>
</RenderPattern>
And the hourField.js
function formatHourField(t) {
var m = t % 60;
var h = (t - m)/ 60;
document.write(h + ":" + m);
}
Having in mind what I've tried before - this solution looks beautifully simple :)
The value that is rendered in the All Items view is not based on the Template or control. It is rendered from the
<RenderPattern Name="DisplayPattern">
<Switch>
<Expr><Column /></Expr>
<Case Value="" />
<Default>
<Column SubColumnNumber="1" HTMLEncode="TRUE" />
<HTML><![CDATA[, ]]></HTML>
<Column SubColumnNumber="0" HTMLEncode="TRUE" />
</Default>
</Switch>
</RenderPattern>
Tag of the Field Schema that you have defined. Display Template Defines the look of how it is being displayed in the Disp Form. Hope this helps.
It will be bit trick to get your format in the CAML Representation .
You can get some infomration about the subject here

Resources