I am trying to display checkboxlist with prechecked items.
The values are saved in a list in my database and for "editing" the user should be able to select new options as well as "uncheck" some of the earlier selected one.
Thats why I need to translate my List back to the checkboxlist...
Any idea how that could possibly work?
Thanks a lot!
I'll give you an example of how you can do it.
[1]edit.jsp page:
It is the page where you want to display your checked checkboxlist:
<s:checkboxlist name="type" list="typeList" />
here "type" is name of checkbox and "typeList" is a list which is loaded from actionclass in my case.
[2]loadEditData method in action class:
public class your_action_class_name extends ActionSupport {
private List<String> type;
private List<String> typeList;
public List<String> getType() {
return type;}
public void setType(List<String> type) {
this.type = type;}
public List<String> getTypeList() {
return typeList;
}
public void setTypeList(List<String> typeList) {
this.typeList = typeList;
}
public String loadEditData(){
tpyeList=\\add whole checkboxlist here;
type.add("value that you want to prechecked");
return SUCCESS;
}
}
[3]struts.xml:
<action name="edit" method="loadEditData" class="your_action_class_Name" >
<result name="success">/edit.jsp</result>
</action>
Now your flow is like follow:
1st call the edit Action that will implement loadEditData method and on returning success display edit.jsp page with checkboxlist which have prechecked value.
Is this answer helpful?
Related
I have a need for a picker-type control in my MAUI app, but the selection list contains over 1000 entries. I don't want to make my users scroll through 1000 entries to find the one they want to choose. Secondarily, that is a lot of data to get from my API every time the page is accessed, but I can figure that out.
Is there something in .Net MAUI that is equivalent to the HTML Datalist, where there's an input box and as the user types, the list condenses down to what they type - like a search box. All I can find on the Microsoft docs is the Picker. I'd like to not have to pay for a third-party control if possible.
https://www.w3schools.com/tags/tag_datalist.asp
Here is what the Search/List looks like -- it could work if
I can prepopulate the field with existing data for that column from the db.
It would show the filtered list as the user types in characters. Currently it opens up blank lines and doesn't show the data.
It does NOT show all 1000+ entries in the List if the Search is blank unless the user is actually on that field. E.g. if you type in a search, then backspace and delete it and move to another field, all List entries remain displayed.
As suggested by Jason ans Steve, you can use a SearchBar with a ListView or CollectionView. Here's the sample code below for your reference:
Model:
public class Notes
{
public string Name { get; set; }
public string Num { get; set; }
}
Xaml:
<VerticalStackLayout>
<SearchBar TextChanged="SearchBar_TextChanged"></SearchBar>
<ListView x:Name="list">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding Name}" Detail="{Binding Num}">
</TextCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</VerticalStackLayout>
Code-behind:
public partial class MainPage : ContentPage
{
public ObservableCollection<Notes> notedata;
public MainPage()
{
InitializeComponent();
//data service
generateData();
BindingContext = this;
}
public void generateData()
{
notedata = new ObservableCollection<Notes>()
{
new Notes(){Name = "alex", Num = "2323423"},
new Notes(){Name = "bloomberg", Num = "12323423"},
new Notes(){ Name = "ahmed", Num = "32323423"},
new Notes(){ Name = "abc", Num = "42323423"},
new Notes(){ Name = "umair", Num = "62323423"},
new Notes(){ Name = "etc", Num = "32323423"},
};
}
private void SearchBar_TextChanged(object sender, TextChangedEventArgs e)
{
//all you need to make a search
if (string.IsNullOrEmpty(e.NewTextValue))
{
list.ItemsSource = notedata;
}
else
{
list.ItemsSource = notedata.Where(x => x.Name.StartsWith(e.NewTextValue));
}
}
}
I am trying to use a property tester on a menu contribution that I have done for my eclipse plugin.
Basically I added a new menu in the main menu bar (by extending menu:org.eclipse.ui.main.menu and adding a menu). I then added my commands in there with the correct handlers.
Everything works as expected.
My only problem is that I am not able to decide when to have them active.
I am trying to use the activeWhen for my handlers. i want them to be active when there is certain data on a server.
I tried using a property tester but it does not get called everytime. It only gets called when you select a different view.
What is the correct way of doing this?
EDIT: here is the code I am using
http://pastebin.com/TGtZaBtM
My property tester runs because I print out stuff when it does.
The only problem is that it does not run every time the menu is opened.
I would like it to run every time so that I can check if a user is logged in or not.
I'm probably answering late...
Anyway to do that, I always define a sourceProvider and some variable using the org.eclipse.ui.services extension point:
As example for a pause action somewhere in a toolbar, here is the piece of code of the source provider and its definition in the plugins.xml:
<extension
point="org.eclipse.ui.services">
<sourceProvider
provider="DataCollectionSourceProvider">
<variable
name="Pause"
priorityLevel="workbench">
</variable>
</sourceProvider>
</extension>
source provider:
public class DataCollectionSourceProvider extends AbstractSourceProvider {
public final static String ID = "DataCollectionSourceProvider";
public final static String ID_PAUSED = "Pause";
public final static String VAL_TRUE = "TRUE";
public final static String VAL_FALSE = "FALSE";
/**
* #return the instance of this source provider in this workbench
*/
public static DataCollectionSourceProvider getInstance() {
ISourceProviderService sourceProviderService = ISourceProviderService)PlatformUI.getWorkbench().getService(ISourceProviderService.class);
DataCollectionSourceProvider dcProvider = (DataCollectionSourceProvider)sourceProviderService.getSourceProvider(ID);
return dcProvider;
}
private boolean paused = false;
public DataCollectionSourceProvider() {
// do nothing
}
#Override
public Map<?, ?> getCurrentState() {
String value = null;
Map<String, String> map = new HashMap<String, String>(2);
// fake variable (my id)
map.put(ID, VAL_TRUE);
// paused state
value = paused ? VAL_TRUE : VAL_FALSE;
map.put(ID_PAUSED, value);
return map;
}
#Override
public String[] getProvidedSourceNames() {
return new String[] { ID, ID_PAUSED };
}
public void setPaused(boolean paused) {
this.paused = paused;
String value = paused ? VAL_TRUE : VAL_FALSE;
fireSourceChanged(ISources.WORKBENCH, ID_PAUSED, value);
}
}
Then on your org.eclipse.ui.handlers contribution, add the enableWhen by using the variable from its defined id:
<extension
point="org.eclipse.ui.handlers">
<handler
commandId="__your_command_id__">
<class
class="__your_handler_class__">
</class>
<enabledWhen>
<with
variable="Pause">
<equals
value="FALSE">
</equals>
</with>
</enabledWhen>
</handler>
</extension>
At last, if you want to update the handler/action state, you just have to call the following piece of code somewhere in your code
DataCollectionSourceProvider.getInstance().setPause(...)
At a quick glance: You are using 'activeWhen' in your handler. You can probably try using 'enabledWhen' in the XML
You can also look into overriding isEnabled() in your Handler. This will work, when your plugin is activated. Look into the docs for more information.
For my Eclipse rcp application I want to use activities to show and hide some views. I read the Eclipse documentation about activities and tried to get a working example based on the 'Using expression-based activities' snippets from the documentation.
In the first step i created a new view and add a placeholder for it in my perspective class:
layout.addPlaceholder(View1.ID, IPageLayout.RIGHT, 0.5f, layout.getEditorArea());
Then i added my activity with a 'enabled when' expression and a binding:
<extension point="org.eclipse.ui.activities">
<activity id="org.project.activities.activity1" name="myActivity">
<enabledWhen>
<with variable="org.project.activities.sessionState">
<equals value="loggedIn"></equals>
</with>
</enabledWhen>
</activity>
</extension>
<activityPatternBinding
activityId="org.project.activities.activity1"
pattern="org.project.activities/org.project.activities.View1">
</activityPatternBinding>
In the last step i added my source-provider:
public class ActivitiySourceProvider extends AbstractSourceProvider {
public static final String SESSION_STATE = "org.project.activities.sessionState";
private static final String LOGGED_OUT = "loggedOut";
private static final String LOGGED_IN = "loggedIn";
private static final String[] SOURCE_NAMES = new String[] { SESSION_STATE };
private boolean loggedIn = false;
#Override
public Map<String, String> getCurrentState() {
Map<String, String> map = new HashMap<String, String>(1);
String value = loggedIn ? LOGGED_IN : LOGGED_OUT;
map.put(SESSION_STATE, value);
return map;
}
#Override
public String[] getProvidedSourceNames() {
return SOURCE_NAMES;
}
public void setLoggedIn() {
loggedIn = !loggedIn;
String value = loggedIn ? LOGGED_IN : LOGGED_OUT;
fireSourceChanged(ISources.WORKBENCH, SESSION_STATE, value);
}
}
When I start the test application my view 'View1' is hidden and when I toggle my variable the view is still hidden. To toggle my variable i used a handle and i don't receive any exceptions. I also tried to set my variable to explicit to 'loggedOut' at the application start, but i didn't worked either.
Did I missed something from the documentation?
Did you register your ActivitySourceProvider as source provider in an extension for extension point org.eclipse.ui.services? Otherwise it won't be used for expression evaluation.
I´ve created an CellTable with the Google Web Toolkit.
I just started using it and my knowledge about it is very small...
However I was searching for a tutorial or just a code example of how to create a checkbox in the CellTable header but everythin I´ve found I didn´t understand or it didn´t worked.
So far I´ve got this code to create a Column for checkboxes and a normal table mostly the same as the Google tutorial for a CellTable:
Column<Contact, Boolean> checkColumn = new Column<Contact, Boolean>(
new CheckboxCell(true, false)) {
#Override
public Boolean getValue(Contact contact) {
return null;
}
};
table.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
table.setColumnWidth(checkColumn, 40, Unit.PX);
Now I´m searching for the code to add a checkbox to the header and how to make it check or uncheck all checkboxes.
Thanks for your time.
From my blog post:
Here is a simple column header that selects/ de-selects all rows in a table. When all rows are checked, the header becomes checked automatically. Clicking the checkbox in the header causes either to select or de-select all rows.
I am using the selection model and the data list provider to do the selection magic. It may not work for everyone.
And here is my custom header:
public final class CheckboxHeader extends Header {
private final MultiSelectionModel selectionModel;
private final ListDataProvider provider;
public CheckboxHeader(MultiSelectionModel selectionModel,
ListDataProvider provider) {
super(new CheckboxCell());
this.selectionModel = selectionModel;
this.provider = provider;
}
#Override
public Boolean getValue() {
boolean allItemsSelected = selectionModel.getSelectedSet().size() == provider
.getList().size();
return allItemsSelected;
}
#Override
public void onBrowserEvent(Context context, Element elem, NativeEvent event) {
InputElement input = elem.getFirstChild().cast();
Boolean isChecked = input.isChecked();
for (TYPE element : provider.getList()) {
selectionModel.setSelected(element, isChecked);
}
}
}
See http://code.google.com/p/google-web-toolkit/issues/detail?id=7014
Hello i have the following problem.
I have a search page lets call it search.xhtml and you can search for a bar-code. This value is unique so the result is always one or zero objects from the database
<p:panelGrid columns="1" style="margin:20px;">
<h:form>
<p:messages id="messages" globalOnly="true" showDetail="false" />
<p:message for="barcode" />
<p:inputText id="barcode" value="#{searchForm.barCode}"
required="true" requiredMessage="Value needed" />
<p:commandButton value="search"
action="#{searchForm.searchBarcode}" id="search"/>
</h:form>
</p:panelGrid>
This is the backingbean:
#ManagedBean
#ViewScoped
public class SearchForm extends BasePage {
private Long barCode;
#ManagedProperty("#{daoManager}")
public DaoManager daoManager;
public void setDaoManager(DaoManager daoManager) {
this.daoManager = daoManager;
}
public Long getBarCode() {
return barCode;
}
public void setBarCode(Long barCode) {
this.barCode = barCode;
}
public String searchBarcode() {
//request to dao to get the object
DataList<Data> data = daoManager.findbybarcode(barCode);
if (data.size() == 0) {
this.addMessage(FacesMessage.SEVERITY_ERROR,
"Not Found: " + barCode);
return null;
} else {
getFacesContext().getExternalContext().
getRequestMap().put("id", data.getId());
return "details";
}
}
So if i go to my details page which expect the parameter id this isnt send to the detail page.
backing bean details page:
#ManagedBean
#ViewScoped
public class DetailBean extends BasePage implements Serializable {
#PostConstruct
public void init() {
if (id != null) {
//Go on with the stuff
} else {
addMessage(FacesMessage.SEVERITY_ERROR,"Object not found");
}
}
}
What am i doing wrong? And is this wrong use of JSF? I know i can generate a list and the click on the result but thats not what i want. Also i can take the barcode from the first bean and pass it as a parameter but i want the details page only to accept the id from the objects. So is my thinking wrong? Or is there a solution to get it like this?
If I understand correctly, you wish to pass the ID of the barcode to the details page and yes this is possible.
getFacesContext().getExternalContext().getRequestMap().put("id", data.getId());
The following line is putting the ID parameter into the request that the client just sent you, but the navigation action to details will result in a different request. Try this instead:
return "details?faces-redirect=true&id=" + data.getId();
This will return an HTTP GET navigation action with the ID of the barcode passed as a request parameter in the request.